package com.atguigu3.common_algorithm.exer1;

/**
 * @author lhl
 * @date 2025/3/31 10:07
 */
public class ArrayExer01 {
    public static void main(String[] args) {
        //1.动态初始化方式创建数组(定义一个int型的一维数组，包含10个元素)
        int[] arr = new int[10];
        //2，通过循环给数组元素赋值(所有随机数都是两位数(int)(Math.random() * (b - a + 1)) +a;。[10,99])
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random() * (90)) +10;
        }
        //3求最大值最小值，总和，平均值
        int max = arr[0];
        int min = arr[0];
        int sum = 0;
        int avg = 0;
        System.out.println("数组元素为：");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
            sum = sum + arr[i];
            if (arr[i] > max) max = arr[i];
            if (arr[i] < min) min = arr[i];
        }
        avg = sum / arr.length;
        System.out.println();
        System.out.println("最大值："+max);
        System.out.println("最小值："+min);
        System.out.println("总和："+sum);
        System.out.println("平均值："+avg);
    }
}
